package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.BasAddress;
import com.wuliu.system.service.IBasAddressService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 用户地址库Controller
 * 
 * @author realue
 * @date 2023-10-28
 */
@Api(tags = {"用户地址库控制器"})
@RestController
@RequestMapping("/system/address")
public class BasAddressController extends BaseController {
    @Resource
    private IBasAddressService basAddressService;

    /**
     * 查询用户地址库列表
     */
    @ApiOperation(value = "查询")
    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasAddress basAddress) {
        startPage();
        List<BasAddress> list = basAddressService.selectBasAddressList(basAddress);
        return getDataTable(list);
    }

    /**
     * 导出用户地址库列表
     */
    @ApiOperation(value = "导出")
    @PreAuthorize("@ss.hasPermi('system:address:export')")
    @Log(title = "用户地址库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasAddress basAddress) {
        List<BasAddress> list = basAddressService.selectBasAddressList(basAddress);
        ExcelUtil<BasAddress> util = new ExcelUtil<BasAddress>(BasAddress.class);
        util.exportExcel(response, list, "用户地址库数据");
    }

    /**
     * 获取用户地址库详细信息
     */
    @ApiOperation(value = "详细")
    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(basAddressService.selectBasAddressById(id));
    }

    /**
     * 新增用户地址库
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "用户地址库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasAddress basAddress) {
        return toAjax(basAddressService.insertBasAddress(basAddress));
    }

    /**
     * 修改用户地址库
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @Log(title = "用户地址库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasAddress basAddress) {
        return toAjax(basAddressService.updateBasAddress(basAddress));
    }

    /**
     * 删除用户地址库
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @Log(title = "用户地址库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(basAddressService.deleteBasAddressByIds(ids));
    }
}
